//
//  AlertViewController.m
//  UITest2
//
//  Created by 夏宇彬 on 15/9/20.
//  Copyright © 2015年 夏宇彬. All rights reserved.
//

#import "AlertViewController.h"

@interface AlertViewController ()
- (IBAction)doAlert:(id)sender;
- (IBAction)doAlertWithButtons:(id)sender;
- (IBAction)doAlertWithInput:(id)sender;
- (IBAction)doActionSheet:(id)sender;
- (IBAction)doReturn:(id)sender;

@property (weak, nonatomic) IBOutlet UILabel *userOutput;

@end

@implementation AlertViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)doAlert:(id)sender {
    UIAlertView* alertDialog;
    alertDialog = [[UIAlertView alloc]
                   initWithTitle:@"Alert Button Selected!" message:@"I need your attention" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
    [alertDialog show];
}

- (IBAction)doAlertWithButtons:(id)sender {
    UIAlertView* alertDialog;
    alertDialog = [[UIAlertView alloc]
                   initWithTitle:@"Alert Button Selected!" message:@"I need your attention" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: @"OK",nil];
    [alertDialog show];
}

- (IBAction)doAlertWithInput:(id)sender {
    UIAlertView* alertDialog;
    alertDialog = [[UIAlertView alloc]
                   initWithTitle:@"Email Address" message:@"Please input your email address" delegate:self cancelButtonTitle:@"Cancel"otherButtonTitles:@"OK", nil];
    alertDialog.alertViewStyle = UIAlertViewStylePlainTextInput;
    [alertDialog show];
}

- (IBAction)doActionSheet:(id)sender {
    UIActionSheet* actionSheet;
    actionSheet = [[UIActionSheet alloc]
                   initWithTitle:@"Available Actions" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destroy" otherButtonTitles:@"OK", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showFromRect:[(UIButton*)sender frame] inView:self.view animated:YES];
}

- (IBAction)doReturn:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString* buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
    
    if ([buttonTitle isEqualToString:@"OK"]) {
        self.userOutput.text = @"You clicked 'OK' button.";
    }
    else if([buttonTitle isEqualToString:@"Cancel"])
    {
        self.userOutput.text = @"You clicked 'Cancel' button.";
    }
    else
    {
        self.userOutput.text = @"You didn't click any button.";
    }
}
@end
